home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: gettimeofday() makes me mad !
- Followup-To: comp.unix.programmer
- Date: Wed, 28 Feb 96 20:13:33 GMT
- Organization: none
- Distribution: inet
- Message-ID: <825538413snz@genesis.demon.co.uk>
- References: <4gnkth$4on@piston.ecp.fr>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4gnkth$4on@piston.ecp.fr> dureta8@cti.ecp.fr "BIG ONE" writes:
-
- > Hello all. If someone could help...
- >
- >COMPILER : gcc, or cc on a Unix system.
- >
- >PROBLEM : I'm trying to make a little program which must repeat an
- >action every .2 second for example ( less than 1 sec anyway). time()
- >wouldn't fit, so I searched and found the function gettimeofday() in
- ><sys/time.h>.
-
- Unfortunately gettimeofday() is not defined by the C language so you should
- discuss it in comp.unix.programmer.
-
- >It gives the time elapsed since 1970 in seconds and
- >microseconds. The problem is that when gettimeofday() is called several
- >times, it finally hangs up ! My program looks like this :
- >
- > struct timeval t ;
- > long useconds ;
- >
- > gettimeofday(&t) ;
-
- On my system gettimeofday takes 2 arguments.
-
- > printf("%ld\n",(usecondes = t.tv_usec)) ;
- >
- > for (;;) {
- > /* ... */ /*this part works fine */
- > gettimeofday(&t) ;
- > if (t.tv_usec > usecondes + 200000) {
-
- Presumably the tv_usec holds the fractional part of the time so cycles
- within a range 0->999999. So if usecondes is 799999 or greater this test can
- never succeed. You will need to formulate the test in terms of both of
- the time components.
-
- Followups set to comp.unix.programmer.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-